import {getViewportRect} from '../shared/util'
export default {
    beforeUpdate(el:HTMLElement,binding:any):void{
        if(!binding.value?.visible)return
        setTimeout(()=>{
            binding.dir.task(el,binding)
        })
	},
    task(el:HTMLElement,binding:any){
        const {arg,value} = binding
        const {left,top,height} = value as Record<string,number>
        const {clientHeight} = getViewportRect()
        const oh = el.offsetHeight
        let x=0 ,y=0;
        switch(arg){
            case 'v':{
                x = left
                if(top+height+oh+5<=clientHeight+10||top-oh-5<=0)
                    y = top+height+5
                else 
                    y = top-oh-5
            }
        }
        el.style.cssText=`left:${x}px;top:${y}px;`
    }
}